namespace pos.entity
{
using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Criterion;
/// <summary>
/// t_scommodity 的摘要说明
/// </summary>
public class t_scommodity:IEntityUtil
{
	//   列名称哈希表 
	private static Hashtable m_colLabels;    	 
	public static Hashtable colLabels//
	{
		get{return m_colLabels;}
	}
	//表字段名称哈希表
	private static ArrayList m_colNames;     
	public static ArrayList  colNames　
	{
		get{return m_colNames;}
	}
	private Scommodity __scommodity;
	public String id  
	{
		get{return __scommodity.id;}
		set{ __scommodity.id=value;}
	}
	public String commodityID  
	{
		get{return __scommodity.commodityID;}
		set{ __scommodity.commodityID=value;}
	}
	public String groupID  
	{
		get{return __scommodity.groupID;}
		set{ __scommodity.groupID=value;}
	}
	public int count  
	{
		get{return __scommodity.count;}
		set{ __scommodity.count=value;}
	}
	public int type  
	{
		get{return __scommodity.type;}
		set{ __scommodity.type=value;}
	}
	public int state  
	{
		get{return __scommodity.state;}
		set{ __scommodity.state=value;}
	}
	public DateTime addTime  
	{
		get{return __scommodity.addTime;}
		set{ __scommodity.addTime=value;}
	}
	private static  ScommodityDao dao=(ScommodityDao)SpringContext.Context.GetObject("ScommodityDao");
	public static ScommodityDao DAO
	{
		get{return dao;}
		
	}
	
	public t_scommodity()
	{
		__scommodity=new Scommodity();
	  	id="";
	  	commodityID="";
	  	groupID="";
	  	count=consts.int_min;
	  	type=consts.int_min;
	  	state=consts.int_min;
	  	addTime=DateTime.Now;
	  // dao=(ScommodityDao)SpringContext.Context.GetObject("ScommodityDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("id", @"主键");
		colNames.Add("id");
		m_colLabels.Add("commodityID", @"商品条形码");
		colNames.Add("commodityID");
		m_colLabels.Add("groupID", @"组名");
		colNames.Add("groupID");
		m_colLabels.Add("count", @"数量");
		colNames.Add("count");
		m_colLabels.Add("type", @"类型");
		colNames.Add("type");
		m_colLabels.Add("state", @"状态");
		colNames.Add("state");
		m_colLabels.Add("addTime", @"时间");
		colNames.Add("addTime");
	  }
	
	}
	public t_scommodity(Scommodity entity )
	{
		__scommodity=entity;
		
	  // dao=(ScommodityDao)SpringContext.Context.GetObject("ScommodityDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("id", @"主键");
		colNames.Add("id");
		m_colLabels.Add("commodityID", @"商品条形码");
		colNames.Add("commodityID");
		m_colLabels.Add("groupID", @"组名");
		colNames.Add("groupID");
		m_colLabels.Add("count", @"数量");
		colNames.Add("count");
		m_colLabels.Add("type", @"类型");
		colNames.Add("type");
		m_colLabels.Add("state", @"状态");
		colNames.Add("state");
		m_colLabels.Add("addTime", @"时间");
		colNames.Add("addTime");
	  }
	
	}
	public Object uniqueResult(DetachedCriteria dc)
    {
        return dao.uniqueResult(dc);
    }
	 public DetachedCriteria DC 
     {
        	get{return DetachedCriteria.For(typeof(Scommodity));}
     }
	public const string ENTITYNAME="t_scommodity";
	public const int SEQN0=288;
	
    public void checkAdd()
    {
		int len;
//do not check id 
 if(id=="0")
	 throw (new Exception("主键是主健，框架要求值不能为0"));				

	
	len=commodityID.Trim().Length;
	if(len>50)
		 throw (new Exception("商品条形码字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("商品条形码不能为空!"));	
	

	
	len=groupID.Trim().Length;
	if(len>50)
		 throw (new Exception("组名字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("组名不能为空!"));	
	

	//try{Convert.ToInt32(count);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	count<consts.int_min+1)
			throw (new Exception("请输入数量"));

	//try{Convert.ToInt32(type);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	type<consts.int_min+1)
			throw (new Exception("请输入类型"));

	//try{Convert.ToInt32(state);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	state<consts.int_min+1)
			throw (new Exception("请输入状态"));

	//try{Convert.ToDateTime(addTime);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	addTime.ToString().CompareTo(consts.datetime_min) <= 0 )
			throw (new Exception("请输入时间"));

//unique="yes" 唯一性验证
    }
    public void checkUpdate()
    {
		int len;
//do not check id 
 if(id=="0")
	 throw (new Exception("主键是主健，框架要求值不能为0"));				

	
	len=commodityID.Trim().Length;
	if(len>50)
		 throw (new Exception("商品条形码字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("商品条形码不能为空!"));	
	

	
	len=groupID.Trim().Length;
	if(len>50)
		 throw (new Exception("组名字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("组名不能为空!"));	
	

	//try{Convert.ToInt32(count);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	count<consts.int_min+1)
			throw (new Exception("请输入数量"));

	//try{Convert.ToInt32(type);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	type<consts.int_min+1)
			throw (new Exception("请输入类型"));

	//try{Convert.ToInt32(state);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	state<consts.int_min+1)
			throw (new Exception("请输入状态"));

	//try{Convert.ToDateTime(addTime);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	addTime.ToString().CompareTo(consts.datetime_min) <= 0 )
			throw (new Exception("请输入时间"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("id", id);
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==1)
			return;
		if(list.Count==0)
			throw (new Exception("该记录已经被删除"));	
		else
			throw (new Exception("改纪录出现重名!"));
    }
    public void add()
    {
        try
        {
            checkAdd();
         	dao.Add(__scommodity);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void delByid()
    {
    
        try
        {
          dao.Delete(__scommodity);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }

    public  void update()
    {
        try
        {
            checkUpdate();
            dao.Update(__scommodity);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void ExecDataUpdate(int rowNo)
    {
		if(m_updateRow==null)
			return;
		int ii=0;
m_updateRow(rowNo,ii++,commodityID);	
m_updateRow(rowNo,ii++,groupID);	
m_updateRow(rowNo,ii++,(				  string.Format("{0}",count)				  )
);	

    }
    public void ExecHeadInsert()
    {
		if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,200,"商品条形码");
			m_insertHead(ii++,200,"组名");
			m_insertHead(ii++,100,"数量");
		}		
    }
    public void ExecDataInsert()
	{
		if(m_insertRow==null)
			return;
		int ii=0;
     	m_insertRow(0,ii++,commodityID);
     	m_insertRow(0,ii++,groupID);
     	m_insertRow(0,ii++,(				  string.Format("{0}",count)				  )
);
    }
    public void ExecDataInsertByQuery(DetachedCriteria dc)
    {
      
         IList list=dao.List(dc); 
        
        if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,200,"商品条形码");
			m_insertHead(ii++,200,"组名");
			m_insertHead(ii++,100,"数量");
		}		
		
      if(m_insertRow!=null)
      {
        int j=0;
        foreach(Scommodity obj in list)			
        {
		  int ii=0;
	     
m_insertRow(j,ii++,obj.commodityID.ToString());
m_insertRow(j,ii++,obj.groupID.ToString());
m_insertRow(j,ii++,(				  string.Format("{0}",obj.count)
				  )
);
		j++;
        }
        

	
       }
    }

    
    public IList List(DetachedCriteria dc)
    {
        try
        {
           
            return dao.List(dc);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
    
    public bool Init(DetachedCriteria dc)
    {
    
    		Scommodity obj=dao.Get(dc);
    		if(obj==null)
    			return false;
    		else
    		{
    			__scommodity=obj;
            	return true;
            }
        
    }
    public static t_scommodity Get(DetachedCriteria dc)
    {
    	
    	Scommodity obj=((ScommodityDao)SpringContext.Context.GetObject("ScommodityDao"))
	 	.Get(dc);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_scommodity( obj );
        
    }
	 public static t_scommodity GetById(String val)
	 {
	 	Scommodity obj=((ScommodityDao)SpringContext.Context.GetObject("ScommodityDao"))
	 	.GetById(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_scommodity( obj );
	 	
	 	
	 }
	 public  bool InitById(String val)
	 {
	 	

	 	Scommodity obj=dao.GetById(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__scommodity=obj;
	 		return true;
	 	}
	 	
	 	
	 }
    
       public bool showInForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["id"]!=null)
		{
			Controls["id"].Text=id;
		}
		if(Controls["commodityID"]!=null)
		{
			Controls["commodityID"].Text=commodityID;
		}
		if(Controls["groupID"]!=null)
		{
			Controls["groupID"].Text=groupID;
		}
		if(Controls["count"]!=null)
		{
			Controls["count"].Text=(				  string.Format("{0}",count)				  )
;
		}
		if(Controls["type"]!=null)
		{
			Controls["type"].Text=(				  string.Format("{0}",type)				  )
;
		}
		if(Controls["state"]!=null)
		{
			Controls["state"].Text=(				  string.Format("{0}",state)				  )
;
		}
		if(Controls["addTime"]!=null)
		{
			Controls["addTime"].Text=			addTime.ToString().CompareTo("1001-1-1")<0?"":string.Format("{0:g}",addTime);
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    public  t_scommodity Init(Scommodity item)
    {
        __scommodity=item;
        return this;
    }

    
     public bool initByForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["id"]!=null)
		{
			
			if(Controls["id"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["id"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{id=v;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("主键格式不正确！！"));
				}
				
			}
			else
			{
				try{id=Controls["id"].Text;}
				catch
				{
					 Controls["id"].Focus();
					throw  (new Exception("主键格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["commodityID"]!=null)
		{
			
			if(Controls["commodityID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["commodityID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{commodityID=v;}
				catch
				{
					 Controls["commodityID"].Focus();
					throw  (new Exception("商品条形码格式不正确！！"));
				}
				
			}
			else
			{
				try{commodityID=Controls["commodityID"].Text;}
				catch
				{
					 Controls["commodityID"].Focus();
					throw  (new Exception("商品条形码格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["groupID"]!=null)
		{
			
			if(Controls["groupID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["groupID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{groupID=v;}
				catch
				{
					 Controls["groupID"].Focus();
					throw  (new Exception("组名格式不正确！！"));
				}
				
			}
			else
			{
				try{groupID=Controls["groupID"].Text;}
				catch
				{
					 Controls["groupID"].Focus();
					throw  (new Exception("组名格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["count"]!=null)
		{
			
			if(Controls["count"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["count"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{count=(v==""?consts.int_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["count"].Focus();
					throw  (new Exception("数量格式不正确！！"));
				}
				
			}
			else
			{
				try{count=(Controls["count"].Text==""?consts.int_min:Convert.ToInt32(Controls["count"].Text));}
				catch
				{
					 Controls["count"].Focus();
					throw  (new Exception("数量格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["type"]!=null)
		{
			
			if(Controls["type"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["type"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{type=(v==""?consts.int_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["type"].Focus();
					throw  (new Exception("类型格式不正确！！"));
				}
				
			}
			else
			{
				try{type=(Controls["type"].Text==""?consts.int_min:Convert.ToInt32(Controls["type"].Text));}
				catch
				{
					 Controls["type"].Focus();
					throw  (new Exception("类型格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["state"]!=null)
		{
			
			if(Controls["state"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["state"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{state=(v==""?consts.int_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["state"].Focus();
					throw  (new Exception("状态格式不正确！！"));
				}
				
			}
			else
			{
				try{state=(Controls["state"].Text==""?consts.int_min:Convert.ToInt32(Controls["state"].Text));}
				catch
				{
					 Controls["state"].Focus();
					throw  (new Exception("状态格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["addTime"]!=null)
		{
			
			if(Controls["addTime"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["addTime"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{addTime=(v==""?new DateTime(1000,1,1):Convert.ToDateTime(v));}
				catch
				{
					 Controls["addTime"].Focus();
					throw  (new Exception("时间格式不正确！！"));
				}
				
			}
			else
			{
				try{addTime=(Controls["addTime"].Text==""?new DateTime(1000,1,1):Convert.ToDateTime(Controls["addTime"].Text));}
				catch
				{
					 Controls["addTime"].Focus();
					throw  (new Exception("时间格式不正确！！"));
				}
				
			}
				
				
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    

}

}
